home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / Z4PFEX.C < prev    next >
C/C++ Source or Header  |  1993-07-02  |  4KB  |  136 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    z4pfex.c
  5. //   Title:    ZIP+4 Engine
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains the expander for the POF file.
  25. //    This module should not use any global variables since it must be 
  26. //    re-entrant.
  27. //
  28. //    The code in this module should be written entirely in C. 
  29. //    Do not use any C++ constructs.
  30. //
  31. //    This module is portable to:
  32. //        DOS 3.X+
  33. //        MS Windows 3.X+
  34. //        OS/2 2.X+
  35. //        OS/2 2.0 PM
  36. //        SCO UNIX.
  37. //
  38. //    The following compilers are supported:
  39. //        MSC 6.0A
  40. //        MSC/C++ 7.0
  41. //        Borland C++ 3.1 for DOS
  42. //        Borland C++ 1.0 for OS/2 2.X
  43. //        SCO UNIX cc
  44. //
  45. //----------------------------------------------------------------------------
  46. #include <z4.h>
  47.  
  48.  
  49. //----------------------------------------------------------------------------
  50. //   Description:    Read a compressed record from the output buffer.
  51. //    Parameters: pblk            Decoder data structure
  52. //                        pctyst        ZIP5 record
  53. //       Returns:    TRUE if successful. 
  54. //                        FALSE if no more records found to decode.
  55. //----------------------------------------------------------------------------
  56. BOOL FN_E Z4PFExpand(PZ4_PF_BLK pblk, PZ4_PF ppf)
  57. {
  58.     PBYTE pb;
  59.     SIZET cb;
  60.  
  61.     Assert(pblk && ppf);
  62.     memset(&pblk->pf, 0, sizeof(pblk->pf));
  63.                                                     // Must be at end of buffer
  64.     if (pblk->cbNext + MAX_FINANCE_BCD + sizeof(USHORT) + MAX_ZIP5_BCD >= pblk->cb)
  65.         return FALSE;
  66.  
  67.     pb = pblk->pb + pblk->cbNext;            // Decode ZIP5
  68.     if (pb[0] == 0)                            // Block not full, but no more records
  69.         {
  70.         pblk->cbNext = pblk->cb;
  71.         return FALSE;
  72.         }
  73.  
  74.     strb2a(pb, MAX_FINANCE_BCD, pblk->pf.szFinance, MAX_FINANCE, TRUE);
  75.     pb += MAX_FINANCE_BCD;
  76.  
  77.     pblk->pf.cZip5 = (SIZET)*(PUSHORT)pb;
  78.     pb += sizeof(USHORT);
  79.  
  80.     cb = MAX_ZIP5_BCD * pblk->pf.cZip5;        
  81.     memcpy(pblk->pf.abZip5, pb, cb);
  82.     pb += cb;
  83.  
  84.     cb = (SIZET)(pb - pblk->pb);
  85.     Assert(cb <= pblk->cb);
  86.     pblk->cbNext = cb;
  87.     *ppf = pblk->pf;                            // Return a copy of the current record
  88.     return TRUE;
  89. }
  90.  
  91.  
  92. //----------------------------------------------------------------------------
  93. //   Description:    Initialize expander
  94. //    Parameters:    pblk            Decoder data structure
  95. //       Returns:    TRUE if successful.
  96. //----------------------------------------------------------------------------
  97. BOOL FN_E Z4PFExpandInitialize(PZ4_PF_BLK pblk)
  98. {
  99.     Assert(pblk);
  100.     memset(pblk, 0, sizeof(Z4_PF_BLK));
  101.     return TRUE;
  102. }
  103.  
  104.  
  105. //----------------------------------------------------------------------------
  106. //   Description:    Reset expander to decode another block of data.
  107. //    Parameters:    pblk            Decoder data structure
  108. //                        pb                Buffer containing compressed data.
  109. //                        cb                Size of buffer.
  110. //       Returns:    TRUE if successful.
  111. //----------------------------------------------------------------------------
  112. BOOL FN_E Z4PFExpandReset(PZ4_PF_BLK pblk, PBYTE pb, SIZET cb)
  113. {
  114.     Assert(pblk);
  115.     pblk->pb = pb;                                // Set decoding pointers
  116.     pblk->cb = cb;
  117.     pblk->cbNext = 0;
  118.     return TRUE;
  119. }
  120.  
  121.  
  122. //----------------------------------------------------------------------------
  123. //   Description:    Terminate expander.
  124. //    Parameters:    pblk        Decoder data structure
  125. //       Returns:    TRUE if successful.
  126. //----------------------------------------------------------------------------
  127. BOOL FN_E Z4PFExpandTerminate(PZ4_PF_BLK pblk)
  128. {
  129.     Assert(pblk);
  130.     memset(pblk, 0, sizeof(Z4_PF_BLK));
  131.     return TRUE;
  132. }
  133. //----------------------------------------------------------------------------
  134. //------------------------------- End of File --------------------------------
  135. //----------------------------------------------------------------------------
  136.